package nezumi.gui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;

import nezumi.Constants;
import nezumi.state.State;

public abstract class AEntity implements IEntity {

	protected final State state;
	protected final Component enclosingComp;
	protected final Dimension canvasSize;

	public AEntity(State state, Component enclosingComp) {
		assert state != null : "state = " + state;
		assert enclosingComp != null : "enclosingComp = " + enclosingComp;

		this.state = state;
		this.enclosingComp = enclosingComp;
		this.canvasSize = this.enclosingComp.getSize();
	}

	/**
	 * From map coordinates to screen coordinates.
	 */
	protected Point translatePoint(final Point point) {

		double newy = Math.abs(this.state.getMapState().getHeight()
				- point.getY());

		final Point p = new Point();
		p.setLocation(point.getX() * canvasSize.width
				/ (Constants.MAP_WIDTH / Constants.MAP_GRANULARITY * 2), newy
				* canvasSize.height
				/ (Constants.MAP_HEIGHT / Constants.MAP_GRANULARITY * 2));
		return p;
	}
}